package com.lzy.cloud.account.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lzy.cloud.account.dto.AccountWalletDto;
import com.lzy.cloud.account.entity.AccountWallet;
import com.lzy.cloud.account.mapper.AccountWalletMapperExt;
import com.lzy.cloud.account.service.AccountWalletService;
import com.lzy.framework.core.orm.db.Pager;
import com.lzy.framework.core.utils.DozerUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AccountWalletServiceImpl implements AccountWalletService {

    @Autowired
    private AccountWalletMapperExt accountWalletMapperExt;

    @Override
    public Long insert(AccountWalletDto accountWalletDto) {
        AccountWallet accountWallet = DozerUtils.map(accountWalletDto, AccountWallet.class);
        return accountWalletMapperExt.insertSelective(accountWallet) > 0 ? accountWallet.getId() : 0;
    }

    @Override
    public int update(AccountWalletDto accountWalletDto) {
        return accountWalletMapperExt.updateByPrimaryKeySelective(DozerUtils.map(accountWalletDto, AccountWallet.class));
    }


    @Override
    public AccountWalletDto findById(Long aLong) {
        return DozerUtils.map(accountWalletMapperExt.selectByPrimaryKey(aLong), AccountWalletDto.class);
    }

    @Override
    public PageInfo<AccountWalletDto> queryAccountWalletList(Pager pager,AccountWalletDto dto) {
        if (pager != null)
            PageHelper.startPage(pager.getPageNum(), pager.getPageSize());
        List<AccountWalletDto> accountWalletDtoList = accountWalletMapperExt.queryAccountWalletList(dto);
        return new PageInfo<>(accountWalletDtoList);
    }

    @Override
    public List<AccountWalletDto> findById(AccountWalletDto dto) {
        return accountWalletMapperExt.findById(dto);
    }

    @Override
    public AccountWalletDto findByMemberIdAndPlatformId(Long memberId,Long platformId) {
        return accountWalletMapperExt.findByMemberIdAndPlatformId(memberId,platformId);
    }
}
